<template>
  <div class="y">
    <div class="x m10px">
      <el-button type="primary" v-html="'新增'" @click="form=$cp(defForm);show = true" />
    </div>
    <el-table :data="data.unit" border stripe highlight-current-row style="width: 100%">
      <el-table-column type="index" label="行号" width="80" />
      <el-table-column prop="id" label="id" width="180" />
      <el-table-column prop="name" label="名称" width="180" />
      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-button type="primary" @click="form=scope.row; show=true" v-html="'修改'" size="mini" />
        </template>
      </el-table-column>
      <el-table-column prop="other.remarks" label="备注" />
    </el-table>
    <createunit :fshow="show" :form="form" @change="change" />
  </div>
</template>

<script>
import createunit from "../components/create/unitA.vue";
export default {
  components: { createunit },
  props: ["data"],
  data() {
    return {
      show: false,
      form: {},
      defForm: { name: "", other: { remarks: "" } }
    };
  },
  watch: {
    data() {
      this.getData(0);
    }
  },
  created() {
    this.getData(1);
  },
  methods: {
    getData(v) {
      // console.log(this.$cp(this.data), v);
    },
    change(a) {
      if (typeof a.show != "undefined") {
        this.show = a.show;
      }
      if (this.$isset(a.form)) {
        let i = this.data.unit.v2item(a.form.id, "id", true);
        if (i) {
          if (a.form.name) this.data.unit[i].name = a.form.name;
          if (a.form.other) this.data.unit[i].other = a.form.other;
        } else this.data.unit.push(a.form);
      }
    }
  }
};
</script>

